<template>
  <a-modal
    title="修改商户组别限额管理"
    v-model="show"
    :maskClosable="false"
    :width="1050"
    placement="right"
    :closable="true"
    @cancel="onClose"
    :footer="null"
    :visiable="bankLevelManagerEditVisiable"
  >
    <a-form :form="form">
      <a-row>修改限额</a-row>
      <a-row>
        <a-col :md="12" :sm="24">
          <a-form-item label="商户组别"
                       v-bind="formItemLayout">
            <a-input v-decorator="['grpDesc',{rules: [{ required: true, message: '必填字段'}]}]" :disabled="true"/>
          </a-form-item>
        </a-col>
        <a-col :md="12" :sm="24">
          <a-form-item label="商户MCC"
                       v-bind="formItemLayout">
            <a-input v-decorator="['industryName',{rules: [{ required: true, message: '必填字段'}]}]" :disabled="true"/>
          </a-form-item>
        </a-col>
      </a-row>
      <a-row>
        <a-col :md="12" :sm="24">
          <a-form-item label="日累计限额"
                       v-bind="formItemLayout">
            <a-input v-decorator="['dayLimitAmt']"/>
          </a-form-item>
        </a-col>
        <a-col :md="12" :sm="24">
          <a-form-item label='月累计限额'
                       v-bind="formItemLayout">
            <a-input v-decorator="['monthLimitAmt']"/>
          </a-form-item>
        </a-col>
      </a-row>

      <a-row>借记限额</a-row>
      <a-row>
        <a-col :md="12" :sm="24">
          <a-form-item label="单笔借记限额"
                       v-bind="formItemLayout">
            <a-input v-decorator="['singleLimitLoanMaxAmt']"/>
          </a-form-item>
        </a-col>
        <a-col :md="12" :sm="24">
          <a-form-item label='日累计借记限额'
                       v-bind="formItemLayout">
            <a-input v-decorator="['dayLimitLoanAmt']"/>
          </a-form-item>
        </a-col>
      </a-row>
      <a-row>
        <a-col :md="12" :sm="24">
          <a-form-item label="月累计借记限额"
                       v-bind="formItemLayout">
            <a-input v-decorator="['monthLimitLoanAmt']"/>
          </a-form-item>
        </a-col>
      </a-row>

      <a-row>贷记限额</a-row>
      <a-row>
        <a-col :md="12" :sm="24">
          <a-form-item label="单笔贷记限额"
                       v-bind="formItemLayout">
            <a-input v-decorator="['singleLimitCreditMaxAmt']"/>
          </a-form-item>
        </a-col>
        <a-col :md="12" :sm="24">
          <a-form-item label='日累计贷记限额'
                       v-bind="formItemLayout">
            <a-input v-decorator="['dayLimitCreditAmt']"/>
          </a-form-item>
        </a-col>
      </a-row>
      <a-row>
        <a-col :md="12" :sm="24">
          <a-form-item label="月累计贷记限额"
                       v-bind="formItemLayout">
            <a-input v-decorator="['monthLimitCreditAmt']"/>
          </a-form-item>
        </a-col>
      </a-row>

    </a-form>

    <div class="drawer-bootom-button">
      <a-popconfirm title="确定放弃编辑？" @confirm="onClose" okText="确定" cancelText="取消">
        <a-button style="margin-right: .8rem">取消</a-button>
      </a-popconfirm>
      <a-button @click="handleSubmit" type="primary" :loading="loading">提交</a-button>
    </div>
  </a-modal>

</template>
<script>

  const formItemLayout = {
    labelCol: {span: 8},
    wrapperCol: {span: 16}
  }
  export default {
    name: 'BankLevelManagerEdit',

    props: {
      bankLevelManagerEditVisiable: {
        default: false
      },
      instId: '',
    },
    data() {
      return {
        data: [],
        suData: [],
        mchntNoLevelInfo: {
          visiable: false
        },
        loading: false,
        formItemLayout,
        form: this.$form.createForm(this),
        validateStatus: '',
        // firstValue: {},
        info: {
        }
      }
    },
    computed: {
      show: {
        get: function () {
          return this.bankLevelManagerEditVisiable
        },
        set: function () {
        }
      }
    },
    mounted() {

    },

    methods: {

      reset() {
        this.loading = false
        this.form.resetFields()
      },
      onClose() {
        this.reset()
        this.$emit('close')
      },
      handleSubmit() {
        this.form.validateFields((err, values) => {
          if (!err) {
            this.setInfoFields()
            debugger;
            this.loading = true
            this.info.instId = this.instId
            this.info.optFlag = 'upd'


            // console.log(this.info)
            this.$put('/admin/quota/bankLevelManager/editBankMCCquota', {
              ...this.info
            }).then((r) => {
              debugger;
              if (r.data.code!='100000'){
                this.loading = false
                this.$message.error(r.data.message)
              }else {
                this.reset()
                this.$emit('success')
              }

            }).catch(() => {
              this.loading = false
            })
          }
        })

      },

      setInfoFields() {
        let values = this.form.getFieldsValue(['grpNo','limitType', 'notDiffAcctId','loanId','creditId','industryType', 'dayLimitAmt', 'monthLimitAmt', 'singleLimitLoanMaxAmt',
          'dayLimitLoanAmt', 'monthLimitLoanAmt', 'singleLimitCreditMaxAmt', 'dayLimitCreditAmt', 'monthLimitCreditAmt' ])
        if (typeof values !== 'undefined') {
          Object.keys(values).forEach(_key => {
            this.info[_key] = values[_key]
          })
        }
      },

      setBankLevelManagerFormValues ({...info}) {
        let fields = ['grpDesc', 'limitType','notDiffAcctId','loanId','creditId','industryName', 'dayLimitAmt', 'monthLimitAmt', 'singleLimitLoanMaxAmt',
          'dayLimitLoanAmt', 'monthLimitLoanAmt', 'singleLimitCreditMaxAmt', 'dayLimitCreditAmt', 'monthLimitCreditAmt' ]
        Object.keys(info).forEach((key) => {
          if (fields.indexOf(key) !== -1) {
            this.form.getFieldDecorator(key)
            let obj = {}
            obj[key] = info[key]
            this.form.setFieldsValue(obj)
          }
        })
        this.suData=info;
      },


    },

  }
</script>


